import Html5 from '@/views/Html'
import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  // {
  //   path: '/h5/',
  //   component: Html5
  // },
  {
    path: '/h5/pages/home/index',
    component: Html5
  },
  {
    path: '/pages/gift/home/activity',
    component: () => import('@/views/songli')
  },
  {
    path: '/pages/cate/cate-list', // ?id=
    component: () => import('@/views/Catelist')
  },
  {
    path: '/pages/detail/detail', // ?id
    component: () => import('@/views/List/Listdetail')
  },
  {
    path: '/pages/detail/comment', // id
    component: () => import('@/views/Comment')
  },
  {
    path: '/pages/jd-union/list',
    component: () => import('@/views/Youhui')
  },
  {
    path: '/pages/jd-union/list/detail',
    component: () => import('@/views/youhuis/youhuidetail')
  },
  {
    path: '/pages/cate/cate-home',
    component: () => import('@/views/List')
  },
  {
    path: '/shopcar',
    component: () => import('@/views/Shopcar')
  },
  {
    path: '/center/home',
    component: () => import('@/views/Center')
  },
  {
    path: '/login',
    component: () => import('@/views/Login')
  },
  {
    path: '/register',
    component: () => import('@/views/Register')
  },
  {
    path: '/h5/pages/store-map/index',
    component: () => import('@/views/index/City')
  },
  {
    path: '/h5/pages/store-map/city',
    component: () => import('@/views/index/CityCode')
  },
  {
    path: '/h5/pages/store-map/search',
    component: () => import('@/views/index/Search')
  }, {
    path: '/pages/uc-scode/index',
    component: () => import('@/views/index/Scode')
  },
  {
    path: '*',
    redirect: '/h5/pages/home/index'
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  const address = ['/center/home', '/pages/uc-scode/index']
  if (address.includes(to.path)) {
    if (localStorage.getItem('username') && (localStorage.getItem('password') || localStorage.getItem('code'))) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
export default router
